﻿@model Transport.Areas.Administrator.Models.CustomerLogoModel
@{
    var photoFileName = string.IsNullOrEmpty(Model.LogoUrl) ? @Url.Content("~/Content/images/no_logo.jpg") : Model.LogoUrl;
}
@using (Html.BeginForm("Save", "CustomerLogo", FormMethod.Post))
{
    <div class="section-header">
        <div class="title">
            <img src="@Url.Content("~/Areas/Administrator/Content/images/ico-catalog.png")" alt="" />
            @(Model.CustomerLogoId > 0 ? "Sửa logo khách hàng" : "Tạo mới logo khách hàng")
        </div>
        <div class="options">
            <button type="submit" name="save" value="Save" tabindex="6" class="t-button">Lưu</button>
            <a href="@Url.Action("index")" tabindex="8" class="t-button">Quay về</a>
        </div>
    </div>
    
    @Html.HiddenFor(model => model.CustomerLogoId)
    @Html.HiddenFor(model => model.LogoUrl, new { id = "hfMainPromoImagePath" })
    <table width="99%">
        <tr>
            <td width="100" class="adminTitle">
                @Html.Label("Tên khách hàng")
                <span class="field_required">*</span>
            </td>
            <td class="adminData">
                @Html.TextBoxFor(model => model.CustomerName)
                @Html.ValidationMessageFor(model => model.CustomerName)
            </td>
        </tr>
        <tr>
            <td width="100" class="adminTitle">
                @Html.Label("Địa chỉ website")
            </td>
            <td class="adminData">
                @Html.TextBoxFor(model => model.HomePageUrl)
                @Html.ValidationMessageFor(model => model.HomePageUrl)
            </td>
        </tr>
        <tr>
            <td width="100" class="adminTitle">
                @Html.Label("Logo khách hàng")
            </td>
            <td class="adminData">
                <img src="@photoFileName" width="100" height="50" id="imgUserImagePath"/>
            </td>
        </tr>
        <tr>
            <td width="100" class="adminTitle">
            </td>
            <td class="adminData">
                <div class="uploadbtn align-left">
                    <input id="fileuploaderUserImage" type="file"/>
                </div>
                <div style="float: left; font-size: 12px; padding-left: 20px;padding-top:10px;">
                    100 x 50px<br>
                    Maximum size of 1MB. JPG, GIF, PNG.</div>
            </td>
        </tr>
    </table>
}
<script src="@Url.Content("~/Scripts/swfobject.js")" type="text/javascript" ></script>
<script src="@Url.Content("~/Scripts/jquery.uploadify.v2.1.4.min.js")" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
    $(window).load(
    function () {
        $("#fileuploaderUserImage").uploadify({
            'sizeLimit': 1024000,
            'uploader': '@Url.Content("~/Scripts/uploadify.swf")',
            'cancelImg': '@Url.Content("~/Content/images/cancel.png")',
            'buttonImg': '@Url.Content("~/Content/images/update_btn.png")',
            'buttonText': 'Upload A File',
            'height': '30',
            'width': '92',
            'script': '@Url.Action("Upload", "CustomerLogo")',
            'folder': '@Url.Content("~/Uploads")',
            'fileDesc': 'Image Files',
            'fileExt': '*.jpg;*.gif;*.png',
            'multi': false,
            'auto': true,
            'onComplete': CompleteUpload,
            'onError': onErrorUpload
        });
        $("#fileuploaderQueue").hide();
    });

    function CompleteUpload(event, queueID, fileObj, response, data) {
        document.getElementById("imgUserImagePath").src = fileObj.filePath;
        document.getElementById("hfMainPromoImagePath").value = fileObj.filePath;
        return;
        //alert(fileObj.filePath + ' files uploaded successfully!');
    };

    function onErrorUpload(a, b, c, d) {
        if (d.status == 404)
            alert("Could not find upload script. Use a path relative to: " + "<?= getcwd() ?>");
        else if (d.type === "HTTP") {
            alert("error " + d.type + ": " + d.status);
        }
        else if (d.type === "File Size") {
            alert(d.type + " Limit: " + d.info / (1024000) + "MB");
        } else
            alert("error " + d.type + ": " + d.text);
    };
</script>